package com.panopset.game.blackjack;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

public class Player {

    @Override
    public String toString() {
        StringWriter sw = new StringWriter();
        int i = 0;
        for (Hand h : hands) {
            sw.append("" + i);
            sw.append("" + h.cards);
            i++;
        }
        return sw.toString();
    }
    public List<Hand> getHands() {
        return hands;
    }

    private final List<Hand> hands = new ArrayList<Hand>();

    public Player(int betAmount, final BlackjackConfig config, final Bankroll br) {
        hands.add(new Hand(betAmount, config, br));
    }

    public synchronized List<Hand> getAllHands() {
        return hands;
    }

    public synchronized Hand getActiveHand() {
        for (Hand h : hands) {
            if (!h.isFinal()) {
                return h;
            }
        }
        return null;
    }

    public synchronized boolean isFinal() {
        return getActiveHand() == null;
    }

}
